//
//  CustomHotLayout.m
//  19_CarHomeWork
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "CustomHotLayout.h"
@interface CustomHotLayout ()
@property (nonatomic, strong) NSMutableArray *attributesArray;
@property (nonatomic, assign) CGFloat contentWidth;
@end

@implementation CustomHotLayout
- (instancetype)init {
    self = [super init];
    if (self) {
        _attributesArray = [NSMutableArray array];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        _attributesArray = [NSMutableArray array];
    }
    return self;
}

//准备开始布局
- (void)prepareLayout{
    CGFloat itemWidth = 0;
    CGFloat x = 20;
    CGFloat margin = 20;
    for (int i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
        
        x += itemWidth + margin;
        itemWidth = 50;
        CGFloat y = 10;
        CGFloat height = 50;
        
        layoutAttributes.frame = CGRectMake(x, y, itemWidth, height);
        [_attributesArray addObject:layoutAttributes];
    }

}
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    return _attributesArray;
}

- (CGSize)collectionViewContentSize {
    return CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds), 200);
    
}


@end
